package io.github.yotta.notice.sms.example.ali;


import io.github.yotta.common.api.model.Response;
import io.github.yotta.notice.common.dto.NoticeSendResponse;
import io.github.yotta.notice.sms.aliyun.channel.AliSmsNoticeChannel;
import io.github.yotta.notice.sms.common.SmsNoticeRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yotta
 * @date 2023/4/30 17:13
 */
@RequestMapping("/api/sms/ali")
@RestController
public class AliSmsExampleController {

    private final AliSmsNoticeChannel aliSmsNoticeChannel;

    public AliSmsExampleController(AliSmsNoticeChannel aliSmsNoticeChannel) {
        this.aliSmsNoticeChannel = aliSmsNoticeChannel;
    }

    @GetMapping()
    public Response<NoticeSendResponse> test() throws Exception {
        final SmsNoticeRequest aliSmsNoticeDto = new SmsNoticeRequest();
        aliSmsNoticeDto.setTenantId("1");
        aliSmsNoticeDto.setSignName("JAVA小站");
        aliSmsNoticeDto.setTemplateCode("SMS_182551100");
        Map<String, Object> templateParam = new HashMap<>();
        templateParam.put("code", "123456");
        aliSmsNoticeDto.setTemplateParam(templateParam);
        aliSmsNoticeDto.setReceivers(Collections.singletonList("15066871302"));
        return aliSmsNoticeChannel.send(aliSmsNoticeDto);
    }
}
